package com.rg1906.web;

import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.rg1906.entity.LoginUser;
import com.rg1906.service.impl.UserListServiceImpl;


@WebServlet("/UserList")
public class UserList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	UserListServiceImpl service=new UserListServiceImpl();
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			HttpSession session = request.getSession();
			LoginUser user = (LoginUser)session.getAttribute("user");
			String loginName = user.getLoginName();//用户登录名
			int rid = user.getRid();//用户权限id
			String likeName = request.getParameter("likeName");//模糊查询的名字	
			String likeRole = request.getParameter("likeRole");//模糊查询的角色id
			String pageNumber;
			String pageSize;
			 pageNumber = request.getParameter("pageNumber");
			 pageSize = request.getParameter("pageSize");
			if(pageNumber==null||pageSize==null) {
				pageNumber="0";
				pageSize="5";
			}
			HashMap<String,Object> map = new HashMap<>();
			List<com.rg1906.entity.UserList> list = service.queryUserList(pageNumber,pageSize,loginName,rid,likeName,likeRole);
			Object total = service.getCount(loginName,rid,likeName,likeRole);
			map.put("rows", list);
			map.put("total", total);
			String jsonString = JSON.toJSONString(map);
			response.getWriter().print(jsonString);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
